# Simple Database Row Import #
Incredibly simple script to import a table's row based on a defined key.

Handy for when collaborating with other developers and you wish to import the chunk of the database they're working on, without receiving the needless bloat of a full database export, or using complicated and monolithic diff scripts.
This script does not require a remote connection!

All you need is a database file that has insert rows; like those generated by [Simple Database Row Export](../../../simple-database-row-export).

ie. *Backup, delete and import all rows from **foo** table with row **bar** that equals **stuff***

This script is companion to [Simple Database Row Export](../../../simple-database-row-export)

### Things to Consider ###
This script will backup and then **delete** all rows matching the defined key; so if you've modified the defined rows yourself, before receiving and importing your co-workers' rows, *your* changes to those rows will be lost!

### What it Does ###
- Creates a backup of the specified database (just in case!)
- **Deletes** the rows in the table specified (this script assumes *you* have not made any changes to these particular rows*)
- Imports the rows from the import file/destination specified

### Please ensure your backup location is *not* in a publicly-accessible directory, as a *full backup* of your database is generated! ###

*The instructions below assume you're on a Linux system, though script will work on any platform that has MariaDB or MySQL installed.*
***
### To Use ###
- Edit the script's configuration to set the path and what table, row and key to target.

- Put database-import.sh somewhere on your system, ie. `/home/myuser/scripts/`

Make the script executable:

```bash
chmod +x /home/myuser/scripts/database-import.sh
```

Create an alias so you can trigger it from anywhere:

```bash
nano ~/.bashrc
```

Add the following to the bottom of your **.bashrc** file:

```bash
alias tblimport='/home/myuser/scripts/database-import.sh'
```

Update your bash config without requiring logout:

```bash
. ~/.bashrc
```

Run `tblimport` in your cli any time you need to export the table rows!
